import { Body, Controller, Get, Post, Req } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { knext } from 'knext';
import { JobTasks } from '@databases/entities/JobTasks';
import { JsonApiResponse } from '@utils/json.api.response';
import { EntityManager, MikroORM } from '@mikro-orm/mysql';
import { InjectEntityManager, InjectMikroORM } from '@mikro-orm/nestjs';

@Controller('task')
export class TaskController {

    constructor(
        @InjectMikroORM('zp')
        private readonly orm : MikroORM,
        @InjectEntityManager('zp')
        private readonly em : EntityManager
    ){
    }

    @Get('hi')
    async hi()
    {
        return JsonApiResponse.string('hi')
    }

    @ApiOperation({summary:'创建任务 (创建 C)'})
    @Post('create')
    async create(
        @Req() request,
        @Body() formData
    )   
     {
            let knex = knext(this)

            let result = await knex.fromORM(JobTasks)
                .insert({
                creator_id:request.user.id,
                owner_id:request.user.id,
                task_ref_id:formData.task_id
            })
     }
}
